<template>
	<view class="container" style="padding-top: 10px;">
		<view class="floor">
			<view class="title">巡检单编号</view>
			<view class="content">
				<input type="text" v-model="dict.seqNo" placeholder="禁止输入巡检单编号" disabled="true" readonly />
			</view>
		</view>
		<view class="floor">
			<view class="title">检查点1</view>
			<view class="content" style="height: 30vh;overflow: overlay;">
				<input type="text" v-model="dict.desPoint01" placeholder="请输入检查点1" />
				<image :src="dict.imgPoint01[0].url" @longtap="deleteIt(1)" v-if="dict.imgPoint01[0].url != ''"></image>
				<button @click="addPic(1)" v-else>+</button>
			</view>
		</view>
		<view class="floor">
			<view class="title">检查点2</view>
			<view class="content" style="height: 30vh;overflow: overlay;">
				<input type="text" v-model="dict.desPoint02" placeholder="请输入检查点" />
				<image :src="dict.imgPoint02[0].url" @longtap="deleteIt(2)" v-if="dict.imgPoint02[0].url != ''"></image>
				<button @click="addPic(2)">+</button>
			</view>
		</view>
		<view class="floor">
			<view class="title">检查点3</view>
			<view class="content" style="height: 30vh;overflow: overlay;">
				<input type="text" v-model="dict.desPoint03" placeholder="请输入检查点3" />
				<image :src="dict.imgPoint03[0].url" @longtap="deleteIt(3)" v-if="dict.imgPoint03[0].url != ''"></image>
				<button @click="addPic(3)">+</button>
			</view>
		</view>
		<view class="floor">
			<view class="title">检查点4</view>
			<view class="content" style="height: 30vh;overflow: overlay;">
				<input type="text" v-model="dict.desPoint04" placeholder="请输入检查点4" />
				<image :src="dict.imgPoint04[0].url" @longtap="deleteIt(4)" v-if="dict.imgPoint04[0].url != ''"></image>
				<button @click="addPic(4)">+</button>
			</view>
		</view>
		<view class="floor">
			<view class="title">检查点5</view>
			<view class="content" style="height: 30vh;overflow: overlay;">
				<input type="text" v-model="dict.desPoint05" placeholder="请输入检查点5" />
				<image :src="dict.imgPoint05[0].url" @longtap="deleteIt(5)" v-if="dict.imgPoint05[0].url != ''"></image>
				<button @click="addPic(5)">+</button>
			</view>
		</view>
		<view class="floor">
			<view class="title">检查点6</view>
			<view class="content" style="height: 30vh;overflow: overlay;">
				<input type="text" v-model="dict.desPoint06" placeholder="请输入检查点6" />
				<image :src="dict.imgPoint06[0].url" @longtap="deleteIt(6)" v-if="dict.imgPoint06[0].url != ''"></image>
				<button @click="addPic(6)">+</button>
			</view>
		</view>
		<view class="floor">
			<view class="title">检查点7</view>
			<view class="content" style="height: 30vh;overflow: overlay;">
				<input type="text" v-model="dict.desPoint07" placeholder="请输入检查点7" />
				<image :src="dict.imgPoint07[0].url" @longtap="deleteIt(7)" v-if="dict.imgPoint07[0].url != ''"></image>
				<button @click="addPic(7)">+</button>
			</view>
		</view>
		<view class="floor">
			<view class="title">检查点8</view>
			<view class="content" style="height: 30vh;overflow: overlay;">
				<input type="text" v-model="dict.desPoint08" placeholder="请输入检查点8" />
				<image :src="dict.imgPoint08[0].url" @longtap="deleteIt(8)" v-if="dict.imgPoint08[0].url != ''"></image>
				<button @click="addPic(8)">+</button>
			</view>
		</view>
		<view class="floor">
			<view class="title">检查点9</view>
			<view class="content" style="height: 30vh;overflow: overlay;">
				<input type="text" v-model="dict.desPoint09" placeholder="请输入检查点9" />
				<image :src="dict.imgPoint09[0].url" @longtap="deleteIt(9)" v-if="dict.imgPoint09[0].url != ''"></image>
				<button @click="addPic(9)">+</button>
			</view>
		</view>
		<view class="floor">
			<view class="title">检查点10</view>
			<view class="content" style="height: 30vh;overflow: overlay;">
				<input type="text" v-model="dict.desPoint10" placeholder="请输入检查点10" />
				<image :src="dict.imgPoint10[0].url" @longtap="deleteIt(10)" v-if="dict.imgPoint10[0].url != ''">
				</image>
				<button @click="addPic(10)">+</button>
			</view>
		</view>
		<view class="floor">
			<view class="title">检查点11</view>
			<view class="content" style="height: 30vh;overflow: overlay;">
				<input type="text" v-model="dict.desPoint11" placeholder="请输入检查点11" />
				<image :src="dict.imgPoint11[0].url" @longtap="deleteIt(11)" v-if="dict.imgPoint11[0].url != ''">
				</image>
				<button @click="addPic(11)">+</button>
			</view>
		</view>
		<view class="floor">
			<view class="title">检查点12</view>
			<view class="content" style="height: 30vh;overflow: overlay;">
				<input type="text" v-model="dict.desPoint12" placeholder="请输入检查点12" />
				<image :src="dict.imgPoint12[0].url" @longtap="deleteIt(12)" v-if="dict.imgPoint12[0].url != ''">
				</image>
				<button @click="addPic(12)">+</button>
			</view>
		</view>
		<view class="floor">
			<view class="title">检查点13</view>
			<view class="content" style="height: 30vh;overflow: overlay;">
				<input type="text" v-model="dict.desPoint13" placeholder="请输入检查点13" />
				<image :src="dict.imgPoint13[0].url" @longtap="deleteIt(13)" v-if="dict.imgPoint13[0].url != ''">
				</image>
				<button @click="addPic(13)">+</button>
			</view>
		</view>
		<button type="primary" style="width: 80%;margin: 20px auto;" @click="sendInfo();">提交</button>
	</view>
</template>

<script>
	import config from '@/config/config.js'
	import {
		flowInspectionGuardInsert,
		flowInspectionGuardEdit,
		fileUpload
	} from "@/api/home.js"
	export default {
		data() {
			return {
				dict: {
					id: '',
					desPoint01: "",
					imgPoint01: [{
						url: '',
						name: ''
					}],
					desPoint02: "",
					imgPoint02: [{
						url: '',
						name: ''
					}],
					desPoint03: "",
					imgPoint03: [{
						url: '',
						name: ''
					}],
					desPoint04: "",
					imgPoint04: [{
						url: '',
						name: ''
					}],
					desPoint05: "",
					imgPoint05: [{
						url: '',
						name: ''
					}],
					desPoint06: "",
					imgPoint06: [{
						url: '',
						name: ''
					}],
					desPoint07: "",
					imgPoint07: [{
						url: '',
						name: ''
					}],
					desPoint08: "",
					imgPoint08: [{
						url: '',
						name: ''
					}],
					desPoint09: "",
					imgPoint09: [{
						url: '',
						name: ''
					}],
					desPoint10: "",
					imgPoint10: [{
						url: '',
						name: ''
					}],
					desPoint11: "",
					imgPoint11: [{
						url: '',
						name: ''
					}],
					desPoint12: "",
					imgPoint12: [{
						url: '',
						name: ''
					}],
					desPoint13: "",
					imgPoint13: [{
						url: '',
						name: ''
					}]
				}
			}
		},
		onLoad(t) {
			console.log('t.item', t.item);
			var x = JSON.parse(t.item);
			console.log(x);
			this.dict = {
				seqNo: x.seqNo,
				id: x.id,
				desPoint01: x.desPoint01,
				imgPoint01: x.imgPoint01,
				desPoint02: x.desPoint02,
				imgPoint02: x.imgPoint02,
				desPoint03: x.desPoint03,
				imgPoint03: x.imgPoint03,
				desPoint04: x.desPoint04,
				imgPoint04: x.imgPoint04,
				desPoint05: x.desPoint05,
				imgPoint05: x.imgPoint05,
				desPoint06: x.desPoint06,
				imgPoint06: x.imgPoint06,
				desPoint07: x.desPoint07,
				imgPoint07: x.imgPoint07,
				desPoint08: x.desPoint08,
				imgPoint08: x.imgPoint08,
				desPoint09: x.desPoint09,
				imgPoint09: x.imgPoint09,
				desPoint10: x.desPoint10,
				imgPoint10: x.imgPoint10,
				desPoint11: x.desPoint11,
				imgPoint11: x.imgPoint11,
				desPoint12: x.desPoint12,
				imgPoint12: x.imgPoint12,
				desPoint13: x.desPoint13,
				imgPoint13: x.imgPoint13
			}
		},
		methods: {
			addPic(t) {
				var that = this;
				uni.chooseImage({
					count: 1,
					success(res) {
						console.log('res', res);
						var arr = res.tempFilePaths;
						for (var i = 0; i < arr.length; i++) {
							uni.uploadFile({
								url: 'https://www.ansteelproperty.com/special/dictionary/files/upload/',
								header: {
									"Authorization": uni.getStorageSync("token"),
									"X-Requested-With": 'XMLHttpRequest',
									"Accept": "application/json"
								},
								method: "post",
								filePath: arr[i],
								fileType: 'image',
								name: 'file',
								formData: {
									'filea': arr[i]
								},
								success: (result) => {
									var json = JSON.parse(result.data);
									if (json.code == 200) {
										const redirectUri = `${config.baseUrl}`
										console.log('redirectUri', redirectUri)
										if (t == 1) {
											that.dict.imgPoint01 = [{
												url: redirectUri + json.msg,
												name: ""
											}]
										} else if (t == 2) {
											that.dict.imgPoint02 = [{
												url: redirectUri + json.msg,
												name: ""
											}]
										} else if (t == 3) {
											that.dict.imgPoint03 = [{
												url: redirectUri + json.msg,
												name: ""
											}]
										} else if (t == 4) {
											that.dict.imgPoint04 = [{
												url: redirectUri + json.msg,
												name: ""
											}]
										} else if (t == 5) {
											that.dict.imgPoint05 = [{
												url: redirectUri + json.msg,
												name: ""
											}]
										} else if (t == 6) {
											that.dict.imgPoint06 = [{
												url: redirectUri + json.msg,
												name: ""
											}]
										} else if (t == 7) {
											that.dict.imgPoint07 = [{
												url: redirectUri + json.msg,
												name: ""
											}]
										} else if (t == 8) {
											that.dict.imgPoint08 = [{
												url: redirectUri + json.msg,
												name: ""
											}]
										} else if (t == 9) {
											that.dict.imgPoint09 = [{
												url: redirectUri + json.msg,
												name: ""
											}]
										} else if (t == 10) {
											that.dict.imgPoint10 = [{
												url: redirectUri + json.msg,
												name: ""
											}]
										} else if (t == 11) {
											that.dict.imgPoint11 = [{
												url: redirectUri + json.msg,
												name: ""
											}]
										} else if (t == 12) {
											that.dict.imgPoint12 = [{
												url: redirectUri + json.msg,
												name: ""
											}]
										} else if (t == 13) {
											that.dict.imgPoint13 = [{
												url: redirectUri + json.msg,
												name: ""
											}]
										}
									}
								}
							});
						}
					}
				})
			},
			deleteIt(t) {
				var that = this;
				uni.showModal({
					title: "提示",
					content: "是否确认删除",
					success(res) {
						if (res.confirm == true) {
							if (t == 1) {
								that.dict.imgPoint01[0].url = "";
							} else if (t == 2) {
								that.dict.imgPoint02[0].url = "";
							} else if (t == 3) {
								that.dict.imgPoint03[0].url = "";
							} else if (t == 4) {
								that.dict.imgPoint04[0].url = "";
							} else if (t == 5) {
								that.dict.imgPoint05[0].url = "";
							} else if (t == 6) {
								that.dict.imgPoint06[0].url = "";
							} else if (t == 7) {
								that.dict.imgPoint07[0].url = "";
							} else if (t == 8) {
								that.dict.imgPoint08[0].url = "";
							} else if (t == 9) {
								that.dict.imgPoint09[0].url = "";
							} else if (t == 10) {
								that.dict.imgPoint10[0].url = "";
							} else if (t == 11) {
								that.dict.imgPoint11[0].url = "";
							} else if (t == 12) {
								that.dict.imgPoint12[0].url = "";
							} else if (t == 13) {
								that.dict.imgPoint13[0].url = "";
							}
						}
					}
				})
			},
			sendInfo() {
				if (this.dict.seqNo) {
					console.log('this.dict', this.dict)
					flowInspectionGuardEdit({
						...this.dict
					}).then(res => {
						if (res.code == 200) {
						console.log('res', res)
							uni.showToast({
								title: "操作成功",
								icon: "none",
								duration: 1000,
								success() {
									uni.navigateBack({
										delta: 1
									})
								}
							})
						} else {
							console.log('res', res)
							uni.showToast({
								title: "操作失败",
								icon: "none"
							})
						}
					}).catch(err => {
						console.log('err', err)
						uni.showToast({
							title: "网络异常",
							icon: "none"
						})
					})
				} else {
					console.log('this.dict', this.dict)
					flowInspectionGuardInsert({
						...this.dict
					}).then(res => {
						if (res.code == 200) {
							uni.showToast({
								title: "操作成功",
								icon: "none",
								duration: 1000,
								success() {
									uni.navigateBack({
										delta: 1
									})
								}
							})
						} else {
							uni.showToast({
								title: "操作失败",
								icon: "none"
							})
						}
					}).catch(err => {
						uni.showToast({
							title: "网络异常",
							icon: "none"
						})
					})
				}

			},
		}
	}
</script>

<style lang="scss" scoped>
	uni-page-body{
		background-color:#fff !important;
	}
	uni-input {
		height: 70rpx !important;
		line-height: 70rpx !important;
	}

	.floor {
		width: 100%;
		overflow: hidden;
		margin-bottom: 5px;

		.title {
			float: left;
			width: 120px;
			line-height: 36px;
			text-align: center;
			font-size: 14px;
			color: #666666;
		}

		.content {
			float: left;
			width: calc(100% - 130px);
			height: 70rpx;
			line-height: 70rpx;
			border-bottom: 1px solid #ccc;

			uni-button {
				width: 120px;
				height: 120px;
				line-height:120px;
				display: block;
				float: left;
				margin: 10px;
			}

			uni-image {
				width: 120px;
				height: 120px;
				line-height:120px;
				display: block;
				float: left;
				margin: 10px;
			}
		}
	}
</style>
</style><style lang="scss" scoped>
	uni-page-body{
		background-color:#fff !important;
	}
	uni-input {
		height: 70rpx !important;
		line-height: 70rpx !important;
	}

	.floor {
		width: 100%;
		overflow: hidden;
		margin-bottom: 5px;

		.title {
			float: left;
			width: 120px;
			line-height: 36px;
			text-align: center;
			font-size: 14px;
			color: #666666;
		}

		.content {
			float: left;
			width: calc(100% - 130px);
			height: 70rpx;
			line-height: 70rpx;
			border-bottom: 1px solid #ccc;

			uni-button {
				width: 120px;
				height: 120px;
				// line-height:120px;
				display: block;
				float: left;
				margin: 10px;
			}

			uni-image {
				width: 120px;
				height: 120px;
				line-height:120px;
				display: block;
				float: left;
				margin: 10px;
			}
		}
	}
</style>